package com.hzw.saas.service.workspace.listener;

import com.hzw.saas.api.workspace.IWorkRecordsService;
import com.hzw.saas.service.workspace.pojo.event.RegisterWorkInstanceEvent;
import com.hzw.saas.service.workspace.pojo.event.SelectWorkInstanceEvent;
import com.hzw.saas.service.workspace.pojo.event.StartWorkInstanceEvent;
import com.hzw.saas.service.workspace.pojo.event.StopWorkInstanceEvent;
import com.hzw.saas.service.workspace.pojo.model.WorkInstance;
import org.springframework.context.event.EventListener;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;

/**
 * <p>
 *
 * </p>
 *
 * @author sonam
 * @since 2021/2/5 16:35
 */
@Slf4j
@Component
@AllArgsConstructor
@Order(9999)
public class WorkRecordListener {

    private final IWorkRecordsService workRecordsService;

    /**
     * 启动
     * @param workInstanceEvent
     */
    @EventListener(StartWorkInstanceEvent.class)
    public void startWorkInstance(StartWorkInstanceEvent workInstanceEvent) {
        WorkInstance workInstance = workInstanceEvent.getWorkInstance();
        //开启产品时增加记录
        workRecordsService.addRecords(workInstance.getInstId(),workInstance.getUserId());
    }

    /**
     *  停止
     * @param workInstanceEvent
     */
    @EventListener(StopWorkInstanceEvent.class)
    public void stopWorkInstance(StopWorkInstanceEvent workInstanceEvent) {
        WorkInstance workInstance = workInstanceEvent.getWorkInstance();
        //开启产品时增加记录
        workRecordsService.updateRecords(workInstance.getUserId());
    }

    /**
     * 查看工作实例
     * @param selectWorkInstanceEvent
     */
    @EventListener(SelectWorkInstanceEvent.class)
    public void selectWorkInstance(SelectWorkInstanceEvent selectWorkInstanceEvent) {
    }

    /**
     * 创建任务定义
     *
     * @param workInstanceEvent
     */
    @EventListener(RegisterWorkInstanceEvent.class)
    public void registerWorkInstance(RegisterWorkInstanceEvent workInstanceEvent) {
    }


}
